const { exec } = require('../db/mysql')

// 获取评论列表
const getCommentList = params => {
  const { id } = params
  let sql = `select * from comments where id='${id}'`
  return exec(sql)
}

// 添加评论
const addComment = params => {
  const { id, text, name, url } = params
  const avatar = `https://avatars.githubusercontent.com/${name}`
  const createTime = new Date().getTime()
  let sql = `insert into comments (id, text, name, url, avatar, createTime) values ('${id}', '${text}', '${name}', '${url}', '${avatar}', '${createTime}')`
  return exec(sql)
}

module.exports = {
  getCommentList,
  addComment
}
